#!/usr/bin/env bash

# c_language.sh

# This file is part of Leah (Language editor and helper).

# Leah is part of Faridayix, an artificially intelligent computer
# operating system.

# Copyright (C) 2010 Scott C. MacCallum
# scottmaccal@gmail.com

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

function c_language 
{
  printf "\n"

  printf "Would you like to insert a standard C template into $file_name? "

  read answer

  if [[ "$answer" == "yes" || "$answer" == "y" ]]; then
    c_language_template
  fi

  if [[ "$answer" == "no" || "$answer" == "n" ]]; then
    printf "\n"

    printf "Understood $USER."
  fi

  printf "\n"

  nl --body-numbering=a --number-width=1 -s " " $file_name

  printf "\n"

  printf "What line would you like to look at? "

  read line_number

  printf "\n"

  printf "Would you like to edit this line or insert an empty line above it? "

  read line_option

  if [[ "$line_option" == "edit" || "$line_option" == "e" ]]; then
    printf "\n"

    printf "What C function would you like to replace line $line_number with? "

    read c_function
  fi

  if [[ "$line_option" == "insert" || "$line_option" == "i" ]]; then
    printf ""
  fi

  if [ "$c_function" == "printf" ]; then
    printf "\n"

    sed -e "$line_number i printf(\"\");" $file_name | nl --body-numbering=a --number-width=1 -s " "

    printf "\n"

    printf "What would you like to add between the quotation marks? "

    read characters

    printf "\n"

    sed -e "$line_number i printf(\"$characters\");" $file_name | nl --body-numbering=a --number-width=1 -s " "

    sed -e "$line_number i printf(\"$characters\");" $file_name > temporary

    sed -e '/^$/d' temporary > $file_name

    rm temporary
  fi
}
#EOF
